<?

class Buffer {

    private static $buffer;

    static function Init() {
        ob_start(__CLASS__ . "::read");
    }

    static function Get($name) {
        if (!isset(self::$buffer[$name])) {
            self::Set($name);
        }
        return "@$name:";
    }

    static function Show($name) {
        if (!isset(self::$buffer[$name])) {
            self::Set($name);
        }
        print "@$name:";
    }

    static function Set($name, $value = false) {
        if ($value) {
            self::$buffer[$name] = array($value);
        } else {
            self::$buffer[$name] = false;
        }
    }
    
    static function Add($name, $value) {
        self::$buffer[$name][] = $value;        
    }

    static function read($buffer) {
        if (!empty(self::$buffer)) {
            foreach (self::$buffer as $name => $values) {
                $buffer = preg_replace("/@$name:/", implode($values), $buffer);
            }
        }
        return $buffer;
    }

}
